import { CartType } from '@/types/cart'
import http from '@/utils/request'

/**
 * 获取新的商品信息
 */
export const getNewCartGoods = (skuId: string) =>
  http({
    url: `/goods/stock/${skuId}`
  })

/**
 * 获取商品的specs和skus
 */
export const getSpecsAndSkus = (skuId: string) =>
  http({
    url: `/goods/sku/${skuId}`
  })

/**
 * 合并购物车
 */
export const mergeLocalCart = (cartList: CartType[]) =>
  http({
    url: `/member/cart/merge`,
    method: 'post',
    data: [...cartList]
  })

/**
 * 获取登录后的购物车列表
 */
export const findCartList = () =>
  http({
    url: '/member/cart'
  })

/**
 * 加入购物车
 */
export const insertCart = (skuId: string, count: number) =>
  http({
    url: `/member/cart`,
    method: 'post',
    data: { skuId, count }
  })

/**
 * 删除商品
 */
export const deleteCart = (ids: string[] | number[]) =>
  http({
    url: `/member/cart`,
    method: 'delete',
    data: { ids }
  })

/**
 * 修改购物车商品的状态和数量
 */
export const updateCart = (goods: CartType) =>
  http({
    url: `/member/cart/${goods.skuId}`,
    method: 'put',
    data: { goods }
  })

/**
 *全选反选
 */
export const checkAllCart = (selected: boolean, ids: string[] | number[]) =>
  http({
    url: `/member/cart/selected`,
    method: 'put',
    data: { selected, ids }
  })
